package seteam12;

public class Cell {
    int line;
    int column;
    int value;

    private boolean isFixed;

    private int boardSize = 9;

    public Cell(int line, int column) {
	this(line, column, 0);
    }

    Cell(int line, int column, int value) {
	this(line, column, value, false);
    }

    Cell(int line, int column, int value, boolean fixed) {
	this.line = line;
	this.column = column;
	this.value = value;
	this.setFixed(fixed);
    }

    public void setOverallSize(int size) {
	boardSize = size;
    }

    int box() {
	assert Math.sqrt(boardSize) * Math.sqrt(boardSize) == boardSize;
	int box = 0;
	int boxSize = Double.valueOf(Math.sqrt(boardSize)).intValue();
	box += 3 * (line / boxSize);
	box += column / boxSize;
	return box;
    }

    public boolean isFixed() {
	return isFixed;
    }

    public void setFixed(boolean isFixed) {
	this.isFixed = isFixed;
    }

    /*
     * Two cells are called equal if they have the same coordinates!
     * 
     * @see java.lang.Object#equals(java.lang.Object)
     */
    @Override
    public boolean equals(Object obj) {
	if (obj == null)
	    return false;
	if (!(obj instanceof Cell))
	    return false;

	Cell rhs = (Cell) obj;
	return (this.line == rhs.line && this.column == rhs.column);
    }

    @Override
    public int hashCode() {
	int hash = 1;
	hash = hash * 31 + Integer.valueOf(line).hashCode();
	hash = hash * 31 + Integer.valueOf(column).hashCode();
	return hash;
    }
}
